#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string pre, mid;
int n;

int dfs(int preL, int preR, int midL, int midR)
{
    if (midL == midR)
        return 1;
    // 找到根的位置
    size_t pos = mid.find(pre[preL]);
    int lsize = pos - midL, rsize = midR - pos;
    int level = 0;
    if (lsize)
        level = max(level, dfs(preL + 1, preL + lsize, midL, pos - 1));
    if (rsize)
        level = max(level, dfs(preL + 1 + lsize, preR, pos + 1, midR));
    return level + 1;
}

int main()
{
    cin >> n;
    cin >> pre >> mid;
    cout << dfs(0, n - 1, 0, n - 1) << endl;
    return 0;
}